#include <iostream>
#include <string>
using namespace std;


int main(){
	string s,t;
	string ans1="",ans2="";
	cin>>s>>t;
	int jnow=0;
	for(int i=0;i<s.length();i++){
		for(int j=jnow;j<t.length();j++){
			if(s[i] == t[j]){
				ans1 += t[j];
				jnow = j+1;
				break;
			}
		}
	}
	jnow = 0;
	for(int i=0;i<t.length();i++){
		for(int j=jnow;j<s.length();j++){
			if(t[i] == s[j]){
				ans2 += s[j];
				jnow = j+1;
				break;
			}
		}
	}
	cout<<(ans1.length()>ans2.length()?ans1:ans2);
	return 0;
}
